package cool.taomu.toolkit.service.centre.kademlia.controller

import cool.taomu.toolkit.service.centre.kademlia.utils.ResourceCollector
import cool.taomu.toolkit.service.kademlia.entity.KPeerNode
import cool.taomu.toolkit.service.kademlia.service.KRoutingTable
import java.util.Set
import javax.inject.Inject
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.core.Response
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.ToString
import org.slf4j.LoggerFactory

@Path("centre")
class ApiController {

    val static LOG = LoggerFactory.getLogger(ApiController);

    @Inject
    ResourceCollector rcollector;
    
    @Inject
    KRoutingTable table
    
    @Accessors
    @ToString
    static class Info{
        KPeerNode node;
        Set<String> serviceNames
        new(KPeerNode node, Set<String> scanResult){
            this.node = node;
            this.serviceNames = scanResult
        }
    }

    @GET
    @Path("/service/name")
    def scan() {
        LOG.info("获取服务中心下的服务名列表")
        var result = new Info(table.localNode,rcollector.scanResult)
        return Response.ok(result).build()
    }
}
